package com.doit.day03

import scala.io.Source


object _01_迭代器 {
  def main(args: Array[String]): Unit = {
    val iterator: MyScalaIterator = new MyScalaIterator
    while (iterator.hasNext){
      val hero: ScalaHero = iterator.next()
      println(hero)
    }
  }
}


class MyScalaIterator extends Iterator[ScalaHero] {
  //打开文件
  val lines: Iterator[String] = Source.fromFile("data/Hero.txt").getLines()

  override def hasNext: Boolean = lines.hasNext

  override def next(): ScalaHero = {
    val str: String = lines.next()
    //3,轮子妈_180::20
    val arr: Array[String] = str.split(",")
    //轮子妈_180::20
    val arr1: Array[String] = arr(1).split("_")
    //180::20
    val arr2: Array[String] = arr1(1).split("::")
    ScalaHero(arr(0).toInt, arr1(0), arr2(0).toInt, arr2(1).toInt)
  }
}


